//
//  TopBarView.m
//  网易新闻头部V2
//
//  Created by qianfeng on 15/9/24.
//  Copyright (c) 2015年 孔令涛. All rights reserved.
//

#import "TopBarView.h"
#import "TopBarCell.h"
#import "AFNetworking.h"
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define StatusBarHeight 20
#define NavigationHeight 44
#define TabBarHeight 49
#define ToolBarHeight 44

@interface TopBarView()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,weak)UITableView * tableview;
@property(nonatomic,copy)NSMutableArray * dataArray;
@end

@implementation TopBarView
+(id)topBarWithIndex:(NSInteger)index UrlString:(NSString *)urlString;
{
    TopBarView * topview = [[TopBarView alloc]initWithFrame:CGRectMake(ScreenWidth * index, 0, ScreenWidth, ScreenHeight-64)];
    topview.backgroundColor = [UIColor colorWithRed:(double)(arc4random()%255) / 255 green:(double)(arc4random()%255) / 255 blue:(double)(arc4random()%255) / 255 alpha:0.5];
    topview.urlString = urlString;
   
    return topview;
}
- (NSMutableArray *)dataArray
{
    if (_dataArray == nil) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
//-(void)loadDataWith:(NSInteger)index
//{
//    [self.dataArray removeAllObjects];
//    AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager];
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//    [manager GET:_urlString parameters:self success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        NSDictionary * dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
//        NSArray * list = dict[@"list"];
//        
//               for (NSDictionary * content in list) {
//            TopBarModel * model = [TopBarModel modelWithDict:content];
//            [self.dataArray addObject:model];
//        }
//         [self creatSubViews];
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        
//    }];
//}
//
- (void)creatSubViews
{

    UITableView * tableView =[[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
    _tableview = tableView;
    _tableview.delegate = self;
    _tableview.dataSource = self;
    [self addSubview:_tableview];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TopBarCell * cell = [TopBarCell cellForRowWithTableView:tableView];
    cell.model = _dataArray[indexPath.row];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 88;
}


@end
